package com.lyl.syt.easyexcel;/**
 * @author Mr.Luo
 * @date 2022-04-29 17:13
 */

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.lyl.syt.model.cmn.Dict;
import com.lyl.syt.service.DictService;
import com.lyl.syt.vo.cmn.DictEeVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr.Luo
 * @date 2022-04-29 17:13
 * @desc
 */
public class DictVoListener extends AnalysisEventListener<DictEeVo> {

    private DictService dictService;

    public DictVoListener(DictService dictService) {
        this.dictService = dictService;
    }

    List<Dict> dictList = new ArrayList<>();

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtil.copyProperties(dictEeVo,dict);
        dictList.add(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        dictService.saveBatch(dictList);
    }
}
